package com.xiaoyao.novel.crawl;

import java.io.IOException;

import com.xiaoyao.novel.pojo.Book;
import com.xiaoyao.novel.pojo.Chapter;
import com.xiaoyao.novel.util.FileUtil;
import com.xiaoyao.novel.util.HttpUtil;

/**
 * 基类
 * 
 * @author 旷明爱
 * @date 2013-8-12 上午09:55:50
 * 
 */
public class BaseCrawl {

	public String tag = "";

	/**
	 * 爬一本书,目录
	 * 
	 * @param bookId
	 */
	public void crawlBook(Book book) {
	}

	/**
	 * 爬章节内容
	 * 
	 * @param chapter
	 * @throws IOException
	 */
	public void crawlChapter(Chapter chapter) throws IOException {
	}

	// ///////////////////////////////////////////
	// ///////////////////////////////////////////
	/**
	 * 过滤
	 * 
	 * @param page
	 * @return
	 */
	public String filter(String page) {
		page = page.replaceAll("<script.+?script>", "");
		page = page.replaceAll("<script.+?/>", "");
		page = page.replaceAll("<a.+?</a>", "");
		page = page.replaceAll("<table.+?table>", "");
		return page;
	}

	public static String downLoadImage(String picUrl, String fileName) {
		byte[] bytes = HttpUtil.getDefault().getPic(picUrl);
		if (bytes == null) {
			fileName = "";
		} else {
			FileUtil.savePic(bytes, fileName);
		}
		return fileName;
	}

}
